package cn.com.xinjinfu.pdoulcProduct.activity.recharge;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import cn.com.xinjinfu.pdoulcProduct.R;
import cn.com.xinjinfu.pdoulcProduct.activity.base.BaseActivity;
import cn.com.xinjinfu.pdoulcProduct.activity.user.MyInvestListAct;
import cn.com.xinjinfu.pdoulcProduct.manager.ActivityManager;
import cn.com.xinjinfu.pdoulcProduct.utils.ReloadUserInfo;
import cn.com.xinjinfu.pdoulcProduct.utils.TextViewUtil;

/**
 * Created by android-adt on 2016/1/26.
 */
public class FixedBuySuccessAct extends BaseActivity {
    private final String ACTION_NAME = "跳转首页广播";
    int objBuy;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_fixed_buy_success);
        ActivityManager.getInstance().addActivity(this);
        Bundle bundle = new Bundle();
        bundle = this.getIntent().getExtras();
        double expectedReturns = bundle.getDouble("expectedReturns");
        double buyAmount = bundle.getDouble("buyAmount");
        objBuy = bundle.getInt("objBuy");
        TextView tv_touzi = (TextView) findViewById(R.id.tv_touzi);
        TextView tv_shouyi = (TextView) findViewById(R.id.tv_shouyi);
        TextView sucess = (TextView) findViewById(R.id.sucess);
        TextView isfast_sucess = (TextView) findViewById(R.id.isfast_sucess);

        tv_shouyi.setText(TextViewUtil.getSumLength(expectedReturns));
        tv_touzi.setText(TextViewUtil.getSumLength(buyAmount));
        sucess.setText("恭喜您，买入成功");

//        if (objBuy == 1) {
//            int regularFirstAward = bundle.getInt("regularFirstAward");
//            if (regularFirstAward != 0) {
//                int x = 1000;
//                if (regularFirstAward == 5000) {
//                    x = 1000;
//                } else if (regularFirstAward == 8000) {
//                    x = 5000;
//                } else if (regularFirstAward == 10000) {
//                    x = 10000;
//                } else if (regularFirstAward == 15000) {
//                    x = 30000;
//                }
//                sucess.setText("恭喜您，首次买入定期成功");
//                isfast_sucess.setVisibility(View.VISIBLE);
//                isfast_sucess.setText("您已完成P兜任务［投资定宝≥" + x + "元］\n" +
//                        "获得" + regularFirstAward + "元活动本金");
//            } else {
//                isfast_sucess.setVisibility(View.GONE);
//            }
//        } else {
//            int transferFirstAward = bundle.getInt("transferFirstAward");
//            if (transferFirstAward != 0) {
//                int x = 1;
//                if (transferFirstAward == 1000) {
//                    x = 1;
//                } else if (transferFirstAward == 2000) {
//                    x = 10;
//                } else if (transferFirstAward == 3000) {
//                    x = 30;
//                }
//                sucess.setText("恭喜您，首次买入转让成功");
//                isfast_sucess.setVisibility(View.VISIBLE);
//                isfast_sucess.setText("您已完成P兜任务［投资转让≥" + x + "份］\n" +
//                        "获得" + transferFirstAward + "元活动本金");
//            } else {
//                isfast_sucess.setVisibility(View.GONE);
//            }
//        }

        findViewById(R.id.bt_touzi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityManager.getInstance().exitActivity();
                Intent mIntent = new Intent(ACTION_NAME);
                mIntent.putExtra("yaner", "home");
                //发送广播
                sendBroadcast(mIntent);
            }
        });

        findViewById(R.id.bt_dingqi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityManager.getInstance().exitActivity();
                Intent intent = new Intent(FixedBuySuccessAct.this, MyInvestListAct.class);
                Bundle mBundle = new Bundle();
                if (objBuy == 2){
                    mBundle.putInt("xItem", 0);//購買轉讓，跳轉到回款列表
                }else {
                    mBundle.putInt("xItem", 1);//直接到投标中列表
                }
                intent.putExtras(mBundle);
                startActivity(intent);
            }
        });

        /**延时3秒*/
        new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                new ReloadUserInfo(FixedBuySuccessAct.this).userRequest();
                return true;
            }
        }).sendEmptyMessageDelayed(0, 1500);


    }

    /**
     * 物理返回键
     */
    @Override
    public void onBackPressed() {
        ActivityManager.getInstance().exitActivity();
        Intent mIntent = new Intent(ACTION_NAME);
        mIntent.putExtra("yaner", "shouye");
        //发送广播
        sendBroadcast(mIntent);
    }
}
